Repository navigation
fix(event_handler): clear Bedrock Agent function context when a tool raises - #8874
Open
hyeonsang010716 wants to merge 2 commits into
Open
hyeonsang010716 wants to merge 2 commits into
hyeonsang010716 wants to merge 2 commits into
Conversation
…raises BedrockAgentFunctionResolver only cleared the context after a tool returned. When the tool raised, the error response was built without clearing it, so data added with append_context carried over to the next invocation on the same warm container. An event missing a required field had the same problem. Clear the context in a finally block in resolve(), as ApiGatewayResolver and AppSyncResolver already do.
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Issue number: closes #8873
Summary
Changes
BedrockAgentFunctionResolveronly cleared the context after a tool returned. When the tool raised,_resolve()built theError: ...response without clearing it, so data added withappend_contextcarried over to the next invocation. An event missing a required field, which makesresolve()raiseValueError, had the same problem.finallyblock inresolve(), as fix(event_handler): clear context when route resolution raises #8539 did forApiGatewayResolverand fix(event_handlers): Bedrock kwargs and media type, AppSync registry and context, Router duplicates, Function URL base path, Depends with classes #8629 did forAppSyncResolver.clear_context()call in_resolve(), sinceresolve()now handles it.User experience
Before: a tool that calls
app.append_context(...)and then raises leaves that data inapp.context, and the next invocation on the same warm container can read it. The repro in #8873 prints{"context_seen": {"user": "alice"}}.After: the context is cleared after every invocation, whether the tool returns, raises, or the event is invalid. The repro prints
{"context_seen": {}}.Verification
Both new tests fail on
developwithassert {'user_id': '12345'} == {}and pass with this change.Tested locally on Python 3.14 with the full
pytest -m "not perf" --ignore tests/e2e,ruff format --check,ruff check,mypyandty. Two logger tests (test_append_context_keys_handles_empty_dict,test_log_dict_key_strip_nones) fail in the full run ondevelopas well and pass on their own, so they are unrelated to this change.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.